import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

import 'package:flutter_admin/models/odoo/stock_quant.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/pages/common/cry/form/cry_input.dart';
import 'package:flutter_admin/pages/common/cry/form1/cry_select.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter_admin/utils/bluetooth.dart';

import 'package:qr_flutter/qr_flutter.dart';
import '../../../../generated/l10n.dart';

class Print extends StatefulWidget {
  Print({this.stockQuant});

  final StockQuant? stockQuant;

  @override
  _PrintState createState() => _PrintState();
}

class _PrintState extends State<Print> {
  late StockQuant stockQuant;
  bool? isAdd;
  List<Uint8List> images = [];
  // ignore: deprecated_member_use
  //List<Uint8List> images = [];
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();
  GlobalKey rootWidgetKey = GlobalKey();
  var configList = [
    {
      "label": "生产单号",
      "key": "productorderno"
    },{
      "label": "产品编码",
      "key": "productCode"
    },{
      "label": "产品名称",
      "key": "productName"
    },{
      "label": "规格型号",
      "key": "productDes"
    },
  ];
  var qrCode = "";

  List<SelectOptionVO> list = [];

  var ishuawei = "0";
  @override
  void initState() {
    super.initState();
    this.isAdd = widget.stockQuant == null;
    this.stockQuant = widget.stockQuant ?? StockQuant();
    this.qrCode = stockQuant.productorderno! + "|" + stockQuant.productCode!;
    list.add(SelectOptionVO(value: "0",label: "其他成品打印"));
    list.add(SelectOptionVO(value: "1",label: "华为成品打印"));
  }

  _capturePng() async {
    formKey.currentState!.save();
    // if(ishuawei == "0"){
    //   showDialog(
    //     context: context,
    //     builder: (BuildContext context) => Dialog(
    //       child: BluetoothView(data: stockQuant.toMap(), configList: configList,qrCode: qrCode,),
    //     ),
    //   ).then((v) {});
    // }else{
    //   // 华为打印
    // }
  }

  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CrySelect(
            label: '打印类型',
            value: ishuawei,
            dataList: list,
            onSaved: (v) {
              ishuawei = v;
            },
          ),
        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: '打印',
          onPressed: () async {
            _capturePng();
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("打印选择"),
      ),
      body: SingleChildScrollView(
        child: form
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}
